package cn.itcast.nems.studentrecord.web.controller.b;

import cn.itcast.nems.studentrecord.constant.ReferenceTypeEnum;
import cn.itcast.nems.studentrecord.dao.dataobject.StudentRecordFundFlowInfoDO;
import cn.itcast.nems.studentrecord.dto.studentrecord.StudentRecordFundFlowInfoDTO;
import cn.itcast.nems.studentrecord.enumeration.FundFlowPaymentTypeEnum;
import cn.itcast.nems.studentrecord.service.studentrecord.StudentRecordFundFlowService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学籍资金流转明细 controller
 **/
@RestController
@RequestMapping("/b/student/record/fund/flow")
@RequiredArgsConstructor
public class StudentRecordFundFlowController {

    private final StudentRecordFundFlowService studentRecordFundFlowService;

    // 补录流水
    @PostMapping
    public ResponseEntity<Boolean> create(@RequestBody StudentRecordFundFlowInfoDO studentRecordFundFlowInfoDO) {
        studentRecordFundFlowInfoDO.setReferenceId(studentRecordFundFlowInfoDO.getPaymentNo());
        studentRecordFundFlowInfoDO.setReferenceLineId(studentRecordFundFlowInfoDO.getPaymentNo());
        StudentRecordFundFlowInfoDTO dto = new StudentRecordFundFlowInfoDTO();
        BeanUtils.copyProperties(studentRecordFundFlowInfoDO, dto);
        if (StringUtils.hasText(studentRecordFundFlowInfoDO.getReferenceType())) {
            dto.setReferenceType(ReferenceTypeEnum.valueOf(studentRecordFundFlowInfoDO.getReferenceType()));
        }
        if (StringUtils.hasText(studentRecordFundFlowInfoDO.getPaymentType())) {
            dto.setPaymentType(FundFlowPaymentTypeEnum.valueOf(studentRecordFundFlowInfoDO.getPaymentType()));
        }
        return ResponseEntity.ok(studentRecordFundFlowService.create(dto));
    }

//    // 修改补录流水
//    @PutMapping
//    public ResponseEntity<StudentRecordFundFlowInfoDO> update(@RequestBody StudentRecordFundFlowInfoDO studentRecordFundFlowInfoDO) {
//        return ResponseEntity.ok(studentRecordFundFlowService.update(studentRecordFundFlowInfoDO));
//    }
//
//    // 删除补录流水
//    @DeleteMapping("/{id}")
//    public ResponseEntity<Boolean> delete(@PathVariable("id") Long id) {
//        return ResponseEntity.ok(studentRecordFundFlowService.delete(id));
//    }


}
